// import { createApp } from 'vue'
// import App from './App.vue'
// import router from './router'
// import store from './store'

// createApp(App).use(store).use(router).mount('#app')
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import {createApp} from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import ElementPLUS from 'element-plus'
import VueAxios from 'vue-axios'
import md5 from 'js-md5';
import MdEditor from 'md-editor-v3';
import 'md-editor-v3/lib/style.css';
import 'element-plus/lib/theme-chalk/index.css'
import './assets/reset.scss'
import './assets/icons/iconfont.css'
import * as filters from './assets/js/filters.js'
const Vue =createApp(App)
Vue.config.productionTip = false
Vue.use(ElementPLUS);
Vue.use(MdEditor)
// axios.defaults.baseURL="http://localhost:3000"
// axios.defaults.headers.post['Access-Control-Allow-Origin'] = 'application/json';
// axios.interceptors.request.use(
//     config => {
//       // console.log(config)
//       // 自定义header信息（比如token）
//       // console.log("请求拦截器添加userId-----------",sessionStorage.userId)
//       if(!config.headers['Access-Control-Allow-Origin']){
//         config.headers['Access-Control-Allow-Origin'] = "http://localhost:3000";
//       }
//       console.log(config)
//       return config;
//     }, function (error) {
//       // 对请求错误做些什么
//       return Promise.reject(error);
//     }
//   );
// Vue.use(md5)
Vue.use(VueAxios,axios)
// Vue.use(md5)
/* eslint-disable no-new */


// Object.keys(filters).forEach(key => { //过滤器挂载在Vue上
//   Vue.filter(key, filters[key])
// })

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
      if (sessionStorage.getItem("token")) {  
          next();
      }
      else {
          next({
              path: '/login',
              query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
          })
      }
  }
  else {
      next();
  }
})
Vue.use(router).mount('#app')